package com.raymond.smgp.msg.tlv;


import com.raymond.cmpp.utils.CommonUtil;

public class TLVFixedString extends TLV {
	private String value;

	private short valueLength;

	public TLVFixedString(short tag, short valueLength) {
		super(tag);
		this.valueLength = valueLength;
	}

	public TLVFixedString(short tag, short valueLength, String value) {
		super(tag);
		this.valueLength = valueLength;
		this.value = value;
	}

	@Override
	public byte[] getValueData()  {
		if(value==null) {
			return null;
		}
		return CommonUtil.ensureLength(value.getBytes(), valueLength);
	}

	@Override
	public void setValueData(byte[] valueData) {
		this.value = new String(valueData);
	}

	@Override
	public short getLength() {
		if (valueLength != 0) {
			return valueLength;
		}
		return (short) value.getBytes().length;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getValue() {
		return value;

	}

}